

package com.hazelcast.aws;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * Query filter to narrow down the scope of the queried EC2 instance set.
 */
final class Filter {

    private final Map<String, String> filters = new HashMap<>();

    private int index = 1;

    void add(String name, String value) {
        filters.put("Filter." + index + ".Name", name);
        filters.put("Filter." + index + ".Value.1", value);
        ++index;
    }

    void addMulti(String name, Collection<String> values) {
        if (!values.isEmpty()) {
            filters.put("Filter." + index + ".Name", name);
            int valueIndex = 1;
            for (String value : values) {
                filters.put(String.format("Filter.%d.Value.%d", index, valueIndex++), value);
            }
            ++index;
        }
    }

    Map<String, String> getFilterAttributes() {
        return new HashMap<>(filters);
    }
}
